package logic

import (
	"context"
	"youngwind-first/demo/internal/svc"
	"youngwind-first/demo/internal/types"
	"youngwind-first/demo/model/gorm_model"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddLogic {
	return &UserAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserAddLogic) UserAdd(req *types.UserAdd) (resp *types.Response, err error) {

	u := gorm_model.User{
		Name: req.Name,
		Age:  req.Age,
	}
	err = l.svcCtx.DbEngin.Create(&u).Error
	if err != nil {
		return nil, err
	}
	resp = new(types.Response)
	resp.Message = "ok"
	return
}
